home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0793 / FCUT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-01  |  4KB  |  119 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 295 of 335                                                               
  3. From : Ian Lin                             1:249/120.0          03 Jul 93  07:03 
  4. To   : Jack Moffitt                                                              
  5. Subj : Overlays                                                               
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  JM> Yes..  but make sure it's a COPY /B <filename.exe>+<filename.ovr>
  8.  
  9. Yup, I'll remember. In fact, I made a neat little program that I found
  10. some use for that in the end you may need to use COPY /B for. It's a simple
  11. little file cutter. I figured I may use ARJ so I can back files up to
  12. multiple volumes, but not all other archivers have that feature so I made
  13. a binary file cutter. Once done though, you'll want to use COPY /B and not
  14. just COPY to put the files back together. And just in case somebody wants
  15. to know what my program looks like, I guess I'll post it now to save the
  16. request message(s), if any would have been. Any suggestions for improvement
  17. would also be appreciated. I also have another one that's for text files
  18. (LCUT). I figured I'd never need one of those, then I downloaded a 600K
  19. text file that listed all files on one of my local boards and I then needed
  20. it! (MS-DOS 6 EDIT can't handle all that!)
  21. ___-- FCUT.PAS ---------}
  22. {$I-,G+}
  23. uses dos,crt;
  24. var
  25.  inf,outf:file;
  26.  k,fnum,v,nrd,nw:word;
  27.  bnum,lim,size:longint;
  28.  b:array [1..20480] of byte;
  29.  p:record
  30.   y:boolean;
  31.   p:word;
  32.  end;
  33. begin
  34.  writeln ('FCUT v2.0');
  35.  if paramcount<3 then begin
  36.   writeln ('Help screen.');
  37.   writeln
  38.    (fexpand(paramstr(0)),' <bytes> <infile> <outfile names 1, 2, 3, etc.>');
  39.   writeln ('Use the /p parameter to pause between files.');
  40.   writeln ('Error codes.'); writeln ('0: not enough parameters');
  41.   writeln ('1: Invalid byte number to cut at');
  42.   writeln ('2: Input file not found'); writeln ('4: Input file is empty');
  43.   writeln ('5: input file also specified for output');
  44.   writeln ('6: Critical write error.');
  45.   halt(0)
  46.  end;
  47.  val (paramstr(1),lim,v);
  48.  if (v<> 0) or (lim<0) then begin
  49.   writeln ('Invalid byte value "',paramstr(1),'"'); halt(1)
  50.  end;
  51.  assign (inf,fexpand(paramstr(2)));
  52.  reset (inf,1);
  53.  if ioresult<>0 then begin
  54.   writeln ('Input file ',fexpand(paramstr(2)),' not found.'); halt(2);
  55.  end;
  56.  if filesize(inf)=0 then begin
  57.   writeln ('Input file '+paramstr(2)+' is empty.'); halt(4);
  58.  end;
  59.  p.y:=false; p.p:=0;
  60.  for fnum:=3 to paramcount do begin
  61.   if (fexpand(paramstr(fnum))=(fexpand(paramstr(2)))) then begin
  62.    writeln ('Error: Input file also specified for output');
  63.    halt(5); end;
  64.   if (paramstr(fnum)='/p') or (paramstr(fnum)='/P') then begin
  65.    p.y:=true; p.p:=fnum; end;
  66.  end;
  67.  fnum:=3;
  68.  repeat
  69.  if p.y then begin
  70.   writeln ('Press a key to continue, any other to detonate...');
  71.   repeat until keypressed;
  72.   v:=word(readkey);
  73.  end;
  74.  if fnum<>p.p then begin
  75.   assign (outf,fexpand(paramstr(fnum)));
  76.   rewrite (outf,1);
  77.   bnum:=0;
  78.   k:=lim div sizeof(b); size:=lim mod sizeof(b);
  79.   if k>0 then
  80.   repeat
  81.    blockread (inf,b,sizeof(b),nrd);
  82.    blockwrite (outf,b,nrd,nw);
  83.    inc(bnum,nw);
  84.    dec(k);
  85.    if nrd<>nw then begin
  86.     writeln ('Critical write error (',fexpand(paramstr(fnum)),')');
  87.     halt(6);
  88.    end;
  89.   until (k=0) or (nrd=0);
  90.   if size>0 then begin
  91.    blockread(inf,b,size,nrd);
  92.    blockwrite(outf,b,nrd,nw);
  93.    inc(bnum,nw);
  94.    if nrd<>nw then begin
  95.     writeln ('Critical write error (',fexpand(paramstr(fnum)),')');
  96.     halt(6);
  97.    end;
  98.   end;
  99.   if (paramcount=fnum) and (not(eof(inf))) then
  100.   repeat
  101.    blockread(inf,b,sizeof(b),nrd);
  102.    blockwrite(outf,b,nrd,nw);
  103.    inc(bnum,nw);
  104.    if nrd<>nw then begin
  105.     writeln ('Critical write error (',fexpand(paramstr(fnum)),')');
  106.     halt(6); end;
  107.   until nrd=0;
  108.   writeln ('Wrote ',bnum,' bytes to ',fexpand(paramstr(fnum)));
  109.   if bnum>lim then
  110.    writeln (bnum-lim,' bytes over cut limit in ',fexpand(paramstr(fnum)));
  111.   close (outf);
  112.   inc (fnum);
  113.  end;
  114.  until (fnum>paramcount) or (eof(inf));
  115.  close (inf);
  116. writeln ('Lum''s Place BBS 613 531 1911 Door games & Files & Soon IMS mail');
  117. writeln
  118.   ('This file cutter util written by NetRunner, co-sysop of Lum''s Place');
  119. end.